<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="file">
        <p v-for="item in arr1" :key="item.name">{{item.name}}</p>
        <button @click="replace">替换</button>
        <button @click="del">删除</button>
        <hr>
        <p v-for="(val, key, index) in obj" :key="index+'obj'">{{val}}</p>
        <button @click="add">新增属性</button>
        <button @click="delObj">删除属性</button>
    </div>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                arr1: [
                    {name: 1},
                    {name: 2},
                    {name: 3},
                    {name: 4}
                ],
                obj: {
                    name: 'Tom',
                    age: 18
                }
            },
            methods: {
                replace() {
                    // 通过数组下标修改完整的一项
                    this.arr1.splice(0, 1, {name: 0})
                },
                del() {
                    // 通过数组length直接修改数组的长度
                    // this.arr1.length = 1
                    this.arr1.splice(1)
                },
                add() {
                    // this.obj.sex = 'nan'
                    this.$set(this.obj, 'sex', 'nan')
                },
                delObj() {
                    this.$delete(this.obj, 'age')
                }
            },
            
        })
    </script>
</body>
</html>